package com.java.gulimall.order.web;

import com.java.gulimall.order.entity.OrderEntity;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.UUID;

/**
 * @author jl
 * Created on 2020/9/12
 */
@Controller
public class HelloController {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping("/test")
    @ResponseBody
    public String testMq() {
        OrderEntity orderEntity = new OrderEntity();
        orderEntity.setOrderSn(UUID.randomUUID().toString());
        // 向交换机发送消息,然后路由到死信队列
        rabbitTemplate.convertAndSend("order-event-exchange","order.create.order",orderEntity,new CorrelationData(UUID.randomUUID().toString()));
        return "OK";
    }

    @GetMapping("/{page}.html")
    public String page(@PathVariable("page") String page) {
        return page;
    }
}
